package com.lyf.jvm.learn.atsgg.memeorygc;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author LYF
 * @date 2022/7/13
 */
public class GcRelativeConcept {
    @Test
    public void test1() throws InterruptedException {
        System.out.println(Runtime.getRuntime().freeMemory());
        GcRelativeConcept g = new GcRelativeConcept();
        System.out.println(Runtime.getRuntime().freeMemory());
        System.gc();
        Runtime.getRuntime().gc();
        System.out.println(Runtime.getRuntime().freeMemory());
        TimeUnit.SECONDS.sleep(3);
        System.out.println(Runtime.getRuntime().freeMemory());
        System.runFinalization();//可确保，强制调用失去引用的finalize
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("回收对象");
        super.finalize();
    }
}
